package com.zhentao.controller;

import com.google.gson.Gson;
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;
import com.mashape.unirest.http.exceptions.UnirestException;
import com.zhentao.pojo.DeepSeekRequest;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

@RestController
@CrossOrigin(origins = "*")
public class AIController {
    private final Gson gson = new Gson();
    @PostMapping("tall")
    public String tallQuestion(@org.springframework.web.bind.annotation.RequestBody String question) throws IOException, UnirestException {

        Unirest.setTimeouts(0, 0);

//DeeseekRequest: 自己的实体类名称

        List<DeepSeekRequest.Message> messages = new ArrayList<>();
//给deepSeek一个角色
        messages.add(DeepSeekRequest.Message.builder().role("system").content("你是一个医学家").build());

// question：说你自己想说的话
        messages.add(DeepSeekRequest.Message.builder().role("user").content(question).build());

        DeepSeekRequest requestBody = DeepSeekRequest.builder()
                .model("deepseek-chat")
                .messages(messages)
                .build();
        HttpResponse<String> response = Unirest.post("https://api.deepseek.com/chat/completions")
                .header("Content-Type", "application/json")
                .header("Accept", "application/json")
                .header("Authorization", "Bearer "+"sk-748c97f103b641a1bd969995ea0bc877")
                .body(gson.toJson(requestBody))
                .asString();
        System.err.println(response.getBody());
        return  response.getBody();
    }
}
